package com.audaque.springboot.foshanupload.web.productdemo.controller;
import com.audaque.springboot.foshanupload.web.productdemo.req.ProductReq;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;

import org.springframework.http.HttpStatus;
import com.audaque.springboot.foshanupload.web.productdemo.service.IProductService;
import com.audaque.springboot.foshanupload.web.productdemo.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;



import io.swagger.v3.oas.annotations.media.Schema;




import lombok.*;


/**
 * <p>
 * 商品 前端控制器
 * </p>
 *
 * @author zgb
 * @since 2024-04-21
 */
@RestController

@Api(value = "商品 前端控制器")

@RequestMapping("/product")
public class ProductController {


    @Autowired
    private IProductService iProductService;

    @PostMapping(value = "/page")
    @ApiOperation(value = "商品 分页查询")
    public Page<Product> page(@RequestBody ProductReq req) {
        QueryWrapper queryWrapper = new QueryWrapper(req);
        Page<Product> page = iProductService.page(new Page<>(req.getCurrent(), req.getSize()),queryWrapper);
        return page;
    }




    @PostMapping(value = "/list")
    @ApiOperation(value = "商品 列表查询")
    public List<Product> list(@RequestBody ProductReq req) {
        QueryWrapper queryWrapper = new QueryWrapper(req);
        List<Product> list = iProductService.list(queryWrapper);
        return list;
    }





    @GetMapping(value = "/{id}")
     @ApiOperation(value = "商品 单体查询")
    public Product getById(@PathVariable("id") String id) {
        Product one=iProductService.getById(id);
        return one;
    }

    @PostMapping(value = "/create")
     @ApiOperation(value = "商品 创建")
    public void create(@RequestBody Product params) {
        iProductService.save(params);
    }

    @PostMapping(value = "/delete/{id}")
     @ApiOperation(value = "商品 删除")
    public void delete(@PathVariable("id") String id) {
        iProductService.removeById(id);
    }

    @PostMapping(value = "/update")
     @ApiOperation(value = "商品 更新")
    public void update(@RequestBody Product params) {
        iProductService.updateById(params);
    }
}
